import axios from 'axios'
// import router from '../router/router.js'

const axiosinstance = axios.create({
  // baseURL:
  //   process.env.NODE_ENV === 'development'
  //     ? process.env.VUE_APP_BASE_URL
  //     : window.domain.url,
  baseURL: "http://127.0.0.1:8888",
  timeout: 6 * 1000,
})

axiosinstance.interceptors.request.use(
  (config) => {
    //  console.log("请求处理中...");
    // 在请求发送之前做一些处理
    // console.log(config.method)
    if(config.method==='get'){
      config.data = JSON.stringify(config.data);
      config.headers['Content-Type'] =
          'application/json;charset=UTF-8'
      config.data  ="true"
    }
    if (!(config.headers['Content-Type'])) {
      if (config.method == 'post') {
        config.headers['Content-Type'] =
          'application/json;charset=UTF-8'
        for (var key in config.data) {
          if (config.data[key] === '') {
            delete config.data[key]
          }
        }
        config.data = JSON.stringify(config.data)
      } else {
        config.headers['Content-Type'] =
          'application/x-www-form-urlencoded;charset=UTF-8'
        config.data = JSON.stringify(config.data)
      }
    }
    return Promise.resolve(config)
  },
  (error) => {
    // 发送失败
    return Promise.reject(error)
  }
)

export default axiosinstance